package com.kermel.andromeda.activities.alarm.add;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.kermel.andromeda.R;
import com.kermel.andromeda.common.action.DialogPromptAction;
import com.kermel.andromeda.data.AlarmSoundModel;

public class ChooseAlarmSoundAction extends DialogPromptAction {
    public AlarmSoundModel model;
    private EditText filenameInput;
    
    public ChooseAlarmSoundAction(Context context, AlarmSoundModel model) {
        super(context);
        this.context = context;
        this.model = model;
    }

    protected Dialog createDialog() {
        Dialog dialog = new Dialog(context);
        dialog.setContentView(R.layout.choose_sound);
        dialog.setTitle(R.string.chooseSoundDialogTitle);
        
        filenameInput = (EditText)dialog.findViewById(R.id.chooseAlarmSoundFilenameInput);
        updateFilenameInputWithDataFromModel();
        
        Button doneButton = (Button)dialog.findViewById(R.id.chooseAlarmSoundDoneButton);
        if (doneButton != null) {
            doneButton.setOnClickListener(new DoneHandler());
        }
        
        return dialog;
    }
    
    private void updateFilenameInputWithDataFromModel() {
        if (filenameInput != null)
            filenameInput.setText(model.filename);
    }
    
    private class DoneHandler implements View.OnClickListener {
        
        public DoneHandler() {
        }
        
        public void onClick(View view) {
            if (filenameInput != null)
                model.filename = filenameInput.getText().toString();
            closeDialog();
        }
    }
}
